package com.kongge.viewdisplayframeworklib.model.queue;


import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.kongge.viewdisplayframeworklib.model.PageNode;
import com.kongge.viewdisplayframeworklib.ui.view.viewscroller.OnPageChangeByScroll;
import com.kongge.viewdisplayframeworklib.ui.view.viewscroller.OnViewChangeListener;
import com.kongge.viewdisplayframeworklib.ui.view.viewscroller.ViewScroller;

import java.util.List;

/**
 * author:kongge
 * date:2018/9/12
 * layout:
 * description:
 */

public class PageQueueScrollerView extends ViewScroller implements IScoller{

    private List<PageNode> pageNodeList;
    private List<View> viewList;


    public PageQueueScrollerView(Context context) {
        super(context);
    }

    public PageQueueScrollerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    @Override
    public void setScrollerTabList(List<PageNode> pageNodes) {
        this.pageNodeList = pageNodes;
    }

    @Override
    public void setScrollerViews(List<View> views, int selectedIndex) {
        if (views == null) {
            return;
        }
        this.viewList = views;
        for (View view : views) {
            addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        }
        initWorkspace(selectedIndex);
//        setSelectIndex(selectedIndex);
    }

    @Override
    public void setPageSelectChangeListener(final OnPageSelectChangeListener listener) {
        setViewChangeListener(new OnViewChangeListener() {
            @Override
            public void onViewChange(int oldIndex, int index) {
                if (listener != null) {
                    listener.onPageSelectChange(PageQueueScrollerView.this, oldIndex, index);
                }
            }

            @Override
            public void onViewLocked(boolean locked) {

            }

            @Override
            public void onNotifyTabbarShouldChange(int index) {

            }
        });
    }

    @Override
    public void setSelectIndex(int index) {
        setCurrentView(index);
    }


}
